package freespiritsocial.io.user.ui.adapter.search

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import freespiritsocial.io.user.R
import freespiritsocial.io.user.data.model.bean.SearchPojo
import freespiritsocial.io.user.databinding.ItemSearchPeopleBinding
import freespiritsocial.io.user.ext.init
import freespiritsocial.io.user.ext.setAdapterAnimation
import freespiritsocial.io.user.viewmodel.SearchViewModel

/**
 * 搜索people
 */
class PeopleAdapter(
    model: SearchViewModel,
    data: ArrayList<SearchPojo> = arrayListOf(),
    layoutResIdRes: Int = R.layout.item_search_people
):
    BaseQuickAdapter<SearchPojo,BaseDataBindingHolder<ItemSearchPeopleBinding>>(layoutResIdRes,data),LoadMoreModule,
    ISearchAdapter by SearchDelegate(SearchViewModel.people,model) {

    init {
        addChildClickViewIds(R.id.iv_avatar)
        setAdapterAnimation(0)
    }

    override fun convert(holder: BaseDataBindingHolder<ItemSearchPeopleBinding>,item: SearchPojo) = with(holder.dataBinding) {
        this?.recyclerViewImage?.init(
            getImageAdapter(item),
            LinearLayoutManager(context,RecyclerView.HORIZONTAL,false),
            hasEmpty = false
        )?.also {
            if (it.itemDecorationCount == 0)
                it.addItemDecoration(spaceItemDecoration)
        }
        this?.people = item.searchPeoplePojo
    }
}